package com.aabte.springcloudlearn.springcloudstream.mypipe;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;

/**
 * @author Daniel
 */
@Slf4j
@EnableBinding(value = {MyPipe.class})
@SpringBootApplication
public class MyPipeStreamApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyPipeStreamApplication.class, args);
    }

    /**
     * 由INPUT接收消息转换成String 类型并打印在控制台上，
     * 然后转换出一个大写的信息返回到OUTPUT中，
     * 通过SendTo注解将方法内返回值转发到其他消息通道中
     */
    @StreamListener(value = MyPipe.INPUT)
    @SendTo(value = {MyPipe.OUTPUT})
    public String handlerToUpperCase(String value) {
        log.info("handlerToUpperCase received: {}", value);
        return value.toUpperCase();
    }

    @StreamListener(value = MyPipe.OUTPUT)
    public void handlerLog(String value) {
        log.info("handlerLog received: {}", value);
    }

}
